from modelscope.pipelines import pipeline
from PIL import Image
from modelscope.outputs import OutputKeys
from modelscope.utils.constant import Tasks
import cv2

if __name__ == "__main__":
    temp_img_path = 'E:/data/code/facechain2/image_of_0.png'
    person_img_path = ('E:/data/open-source/facechain/worker_data/qw/training_data/ly261666/cv_portrait_model/person1'
                       '-15_labeled/0.png')

    image_face_fusion = pipeline('face_fusion_torch', model='damo/cv_unet_face_fusion_torch', model_revision='v1.0.8')
    temp_img = Image.open(temp_img_path)
    person_img = Image.open(person_img_path)
    result = image_face_fusion(dict(template=temp_img, user=person_img))[OutputKeys.OUTPUT_IMG]
    # temp_img.save("temp_of_0.png")
    cv2.imwrite("result_of_0.png", result)
    # result.save("result_of_0.png")
